<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>切换会员</title>
    <meta name="viewport" content="user-scalable=no">
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" href="static/weixin/plug/weui/css/weui.css">
	<link rel="stylesheet" href="static/weixin/plug/weui/css/jquery-weui.css">
	<link rel="stylesheet" type="text/css" href="static/weixin/css/common.css">
	<script type="text/javascript" src="static/weixin/js/myJs.js"></script>
  </head>

  <body>
  	<div class="divcss5">
  		<!-- <p class="login_title">会员绑定</p> -->
	    <form action="weixin/vip/bind" name="Form" id="Form" method="post">
	    	<input type="hidden" name="openid" id="openid" value="${pd.openid}"/>
	    	<div class="login_list">
	    		<span>卡号</span>
			    <input type="number" pattern="[0-9]*" name="kh" id="kh" placeholder="请输入卡号" >
			</div>
			<!-- <div class="login_list">
		      	<span>密码</span>
		      	<input type="password" name="mm" id="mm" placeholder="请输入密码">
	    	</div> -->
	    	<div class="login_list">
		      <span>手机号码</span>
		      <input type="number" name="sjh" id="sjh" pattern="[0-9]*" placeholder="请输入手机号码" maxlength="11" >
		    </div>
				<div class="login_list1">
					<span>验证码</span>
					<input type="number" pattern="[0-9]*" v-model="login_info.verification" id="verification" placeholder="请输入验证码" maxlength="6" >
					<label id="verification_btn" class="weui-btn weui-btn_plain-primary">获取验证码</label>
				</div>
				<div class="login_btn">
					<input class="weui-btn weui-btn_primary" type="submit" onclick="return checkNull()"  value="确认绑定">
				</div>
	    </form>
	      	<p class="login_bound">
	      		注意:此手机号为被绑定卡号所关联的手机号
	      	</p>
	      	
    </div>
		<script type="text/javascript" src="static/weixin/js/jquery-2.1.3.min.js"></script>
		<script type="text/javascript" src="static/weixin/plug/weui/js/jquery-weui.js"></script>
    <script type="text/javascript">
    	var randomNum;
		$(function(){
				$("#verification_btn").on("click",function(){
					var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
					if(!myreg.test($("#sjh").val())) { 
					    $.toast("请输入有效的手机号码！", "text");
					    return false; 
					}
					var _this = this;
					if($(this).hasClass('weui-btn_plain-disabled')){
						$.toast("请一分钟后再次获取验证码", "text");
					}else{
						$.ajax({
							type: "post",
							url: '<%=basePath%>weixin/vip/sendMsg?tm='+new Date().getTime(),
					    	data: {sjh: $("#sjh").val()},
							dataType:'json',
							cache: false,
							success: function(data){
								console.log(data);
								if (data.result.status == 2) {
									$.toast(data.result.msg, "text");
									return;
								}
								if (data.result.status == 1) {randomNum = data.randomNum;
									//$("#verification_btn").addClass("weui-btn_plain-disabled").html("已发送");
									//$.toast("发送成功" + randomNum, "text");
									settime($("#verification_btn"));
									/* task = setTimeout(function(){
										$(_this).removeClass("weui-btn_plain-disabled");
										$("#verification_btn").html("获取验证码");
									},60000); */
								}
							},
							error: function(){
								$.toast("程序异常", "text");
								return;
							}
						});
					}
				})
			})
var countdown=60;
function settime(obj) { //获取验证码倒计时
   if (countdown == 0) { 
       obj.removeClass("weui-btn_plain-disabled").html("获取验证码");
       countdown = 60; 
       return;
   } else {
	obj.addClass("weui-btn_plain-disabled");
	obj.html("重新发送(" + countdown + ")");
	countdown--; 
   } 
setTimeout(function() { 
    settime(obj) }
    ,1000) 
}
	    function checkNull() {
				//$("input[type$='text']").each(function(n) {
				var rs = true;
				$("input").each(function(n) {
					if ($(this).val() == "") {
						// $(this).attr("placeholder", $(this).attr("placeholder") + " 不能为空");
						$(this).attr("class", "invalid");
						rs = false;
					}
				});
				if (!rs) return rs;
				if (randomNum != $("#verification").val()) {
					rs = false;
					$.toast("验证码错误", "text");
				}
				
				return rs;
			}
    </script>
  </body>
</html>
